﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeiboFilter.DAL;
using WeiboFilter.Models;
using WeiboFilter.KeywordsRelated;

namespace WeiboFilter
{
    public partial class Like : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id=Request.QueryString[0];
            string flag = Request.QueryString[1];
            StatusDAL sd = new StatusDAL();

            switch (flag)
            {
                case "Like":
                    //喜欢操作的逻辑
                    //更新微博状态
                    sd.UpdateWeiBoStatusState(id, (int)Stat.Like, Session["customer"].ToString(), 100);
                    //提取该条关键字，并将关键字分数打入数据库中
                    //正分
                    OperateLikeHate(sd.GetStatusById(id), true);
                    break;
                case "Hate":
                    sd.UpdateWeiBoStatusState(id, (int)Stat.Hate, Session["customer"].ToString(), -100);
                    //不喜欢操作的逻辑
                    //负分
                    OperateLikeHate(sd.GetStatusById(id), false);
                    break;
                default:
                    break;
            }
            Response.Write("Success");
        }


        private void OperateLikeHate(Status s, bool like)
        {
            WordsDAL wD = new WordsDAL(Session["customer"].ToString());
            KeyWords kkk = new KeyWords(s.text);//依仗关键字提取
            int sign = -1;
            if (like) sign = 1;
            foreach (WordWeight kw in kkk.words)
            {
                Word w = new Word();
                w.content = kw.word;
                w.point = kw.weight * sign;
                w.times = 1;
                wD.UpdateWordInfo(w);
            }
        }
    }

     
}